package controllers;

import models.DesktopModel;
import mvc.IController;

public class DesktopController implements IController
{

	public DesktopController(DesktopModel desktop)
	{
		itsDesktopModel = desktop;
	}
	
	@Override
	public void onAction(String description)
	{
		String [] tokens = description.split("\\s");
		if(tokens.length == 2 && tokens[0].equals("createSurvey"))
		{
			String filename = new String(tokens[1]);
			itsDesktopModel.createSurvey(filename);
		}
		else if(tokens.length == 2 && tokens[0].equals("editSurvey"))
		{
			String filename = new String(tokens[1]);
			itsDesktopModel.editSurvey(filename);
		}
		else if(tokens.length == 5 && tokens[0].equals("takeSurvey"))
		{
			itsDesktopModel.takeSurvey(tokens[1], tokens[2], tokens[3], tokens[4]);
		}
		else if(tokens.length == 2 && tokens[0].equals("gradeSurvey"))
		{
			itsDesktopModel.gradeSurvey(tokens[1]);
		}
		else if(tokens.length == 2 && tokens[0].equals("viewResults"))
		{
			itsDesktopModel.viewResults(tokens[1]);
		}
		else if(tokens.length == 1 && tokens[0].equals("?"))
		{
			System.out.println("[Desktop View]");
			System.out.println("Usage:");
			System.out.println("createSurvey [full file path including filename]- create a survey");
			System.out.println("editSurvey [full file path including filename] -  edit a survey");
			System.out.println("takeSurvey [first name] [last name] [survey file name] [results file name] -  take a survey");
			System.out.println("viewResults [resultsFilename]  : view results of a previouslt taken survey");
			System.out.println("gradeSurvey [resultsFilename] : grade a survey");
			System.out.println("q - quit");
			System.out.println("? - print usage");
			
		}
		else if(tokens.length == 1 && tokens[0].equals("q"))
		{
			System.out.println("Quitting Survey Blaster, kthbye!");
			System.exit(0);
		}
		else
		{
			System.out.println("Wrong command format, type ? for help");
		}
	}

	
	private DesktopModel itsDesktopModel;
}
